package com.shxzz.easy12306.services.user.serialize;

import cn.hutool.core.util.DesensitizedUtil;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

/**
 * 证件号脱敏序列化器
 * @author shxzz
 * @create 2024-02-29-21:54
 */
public class IdCardDesensitizationSerializer extends JsonSerializer<String> {
    @Override
    public void serialize(String idCard, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        String desensitizedIdCard = DesensitizedUtil.idCardNum(idCard, 4, 4);
        jsonGenerator.writeString(desensitizedIdCard);
    }
}
